<?php
$params = require(__DIR__ . '/params.php');
$config = [
    'id' => 'basic',
    'timeZone'=>'Asia/Shanghai',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'defaultRoute' => 'index',
    'language' => 'zh-cn',
    'charset' => 'utf-8',
    'components' => [
        //权限的设置关联文件console.php
        'authManager' => [
            'class' => 'yii\rbac\DbManager',
            'itemTable'=>'{{%auth_item}}',//auth_item (role permission)
            'itemChildTable'=>'{{%auth_item_child}}', //auth_item_child(role->permission)
            'assignmentTable'=>'{{%auth_assignment}}', //auth_assignment (user->role)
            'ruleTable'=>'{{%auth_rule}}', //auth_rule(rule)
            'defaultRoles' => ['default'],//加入rbac的默认权限，如果是admin和default，是合并权限集合的
        ],
        //对资源包进行压缩statrt
        'assetManager'=>[
            //'class' => 'yii\web\AssetManager',
            'class' => 'app\assets\AdminAssetManager',
            'appendTimestamp' => true,
            'bundles'=>[
                'yii\web\JqueryAsset' =>[
                    'js' => [
                        YII_ENV_DEV ? 'jquery.js':'jquery.min.js',
                    ],
                ],
                'yii\bootstrap\BootstrapAsset' =>[
                    'css'=>[
                        YII_ENV_DEV?'css/bootstrap.css':'css/bootstrap.min.css',
                    ],
                ],
                'yii\bootstrap\BootstrapPluginAsset' =>[
                    'js'=>[
                        YII_ENV_DEV?'js/bootstrap.js':'js/bootstrap.min.js',
                    ],
                ],
            ],
        ],
        //对资源包进行压缩end,改完之后，在入口文件index.php中把dev改成prod
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'buscard-admin',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        //前台用户登录验证的用法start
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
            'loginUrl' =>['/member/auth'], //没有登录用户跳到这个页面
            'idParam' => '__user',//防止前后的session相互覆盖，所以要加idParam
            'identityCookie' =>['name'=>'__user_identity','httpOnly' => true],//防止前后的cookie相互覆盖，所以要加identityCookie,httpOnly:只能通过http来传输cookie
        ],
        //前台用户登录验证的用法end
        //后台用户登录验证的用法start
        'admin' => [
            'class' => 'yii\web\User',
            'identityClass' => 'app\modules\models\Admin',
            'enableAutoLogin' => true,
            'loginUrl' =>['/admin/public/login'], //没有登录用户跳到这个页面
            'idParam' => '__admin',//防止前后的session相互覆盖，所以要加idParam
            'identityCookie' => ['name'=>'__admin_identity','httpOnly' => true],//防止前后的cookie相互覆盖，所以要加identityCookie，httpOnly:只能通过http来传输cookie
        ],
        //后台用户登录验证的用法end
        'errorHandler' => [
            'errorAction' => 'admin/public/error',//设置错误页面，必须是继承controller的类的方法
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',//发送邮件的一个类
            'useFileTransport' => false,
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.163.com',
                'username' => 'chaersiyaojinjin@163.com',
                'password' => 'chaersi83331319',
                'port' => '465',
                'encryption' => 'ssl',
            ],
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    //日志需要记录的等级
                    'levels' => ['info','error', 'warning'],
                    //存储目标文件
                    //'logFile' => dirname(__DIR__) . '/runtime/logs/app_' . date('Ymd') . '.log',
                    //需要记录的变量 $_COOKIE  $_SERVER
                    //'logVars' => [],
                ],
            ],
        ],
        'db' => require(__DIR__ . '/db.php'),//连接数据库的地方
        //http://jd.test.com/index/index这种结构模式访问
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
            ],
        ],
    ],
    'params' => $params,//菜单列表合并
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        'allowedIPs' => [$_SERVER["REMOTE_ADDR"]],
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        'allowedIPs' => ['127.0.0.1'],
    ];
}

$config['modules']['admin'] = [
    'class' => 'app\modules\admin',
];
return $config;
